package com.zsix.system.strategy.copyFor;

import com.zsix.system.mapper.taskAssigneeMapper.CopyForMapper;
import com.zsix.system.strategy.manager.CopyForManager;
import com.zsix.common.dto.controllerParams.CCParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Component
public class CCByPositionStrategy implements CCStrategy {
    @Autowired
    private CopyForManager copyForManager;
    @Autowired
    private CopyForMapper copyForMapper;
    /**
     * 设置抄送岗位
     * @param ccParams
     * @return
     */
    @Override
    public String setCCData(CCParams ccParams){
        return copyForManager.setCCData(ccParams);
    }
    /**
     * 获取抄送设置的人员信息
     * @param ccParams
     * @return
     */
    @Override
    public List<HashMap<String,Object>> getSelectData(CCParams ccParams){
        List<HashMap<String,Object>> hashMapList=
                Optional.ofNullable(copyForMapper.selectByStationData(ccParams))
                .map(list->list.stream()
                        .map(it->{
                            HashMap<String,Object> hashMap=new HashMap<>();
                            hashMap.put("id",it.getId());
                            hashMap.put("name",it.getName());
                            return hashMap;
                        })
                        .collect(Collectors.toList())).orElse(new ArrayList<>());
        return hashMapList;
    }
    /**
     * 服务类型
     * @return
     */
    @Override
    public String getType(){
        return "byPositions";
    }
}
